﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using ProjectManagement.Domain.AutoMappings;
using ProjectManagement.Domain.Entities;
using NHibernate.Linq;

namespace ProjectManagement.Domain.Services
{
	public class ControllerActionService
	{
		private static ISessionFactory factory = NHibernateHelper.CreateSessionFactory();
		private static ISession session = factory.OpenSession();
		/// <summary>
		/// 根据id查询对应权限
		/// </summary>
		/// <param name="id">权限Id</param>
		/// <returns>权限类</returns>
		public ControllerAction QueryControllerActionById(int id)
		{
			return session.Query<ControllerAction>()
				.Where(c => c.ID == id)
				.FirstOrDefault();
		}
		/// <summary>
		/// 查询所有权限
		/// </summary>
		/// <returns></returns>
		public IEnumerable<ControllerAction> QueryAllConAction()
		{
			return session.Query<ControllerAction>()
				.ToList();
		}
		/// <summary>
		/// 根据主权限查询下级权限
		/// </summary>
		/// <param name="parentId">主权限ID</param>
		/// <returns></returns>
		public IEnumerable<ControllerAction> QuerySecondByMainId(int parentId)
		{
			return session.Query<ControllerAction>()
				.Where(c => c.ParentMenu == parentId)
				.Where(c => c.MainMenu == false)
				.ToList();
		}

	}
}
